package com.zbf.role;

import com.github.pagehelper.PageInfo;
import com.zbf.common.entity.ResponseResult;
import com.zbf.common.entity.ResponseResultEnum;
import com.zbf.dao.RoleDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 作者: LCG
 * 日期: 2020/6/9 20:35
 * 描述: 角色管理
 */
@RestController
@RequestMapping("role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    /**
     * 获取角色列表数据
     * @param map
     * @return
     */
    @RequestMapping("/getPageRole")
    public ResponseResult getPageRole(@RequestBody Map<String,Object> map){
        PageInfo<Map<String, Object>> pageRole = roleService.getPageRole(map);
        ResponseResult responseResult=ResponseResult.getResponseResult();
        responseResult.setResult(pageRole);
         return responseResult;
    }


    /**
     * 根据角色名称获取角色的列表
     */
    @RequestMapping("/getRoleList")
    public ResponseResult getRoleist(@RequestBody Map<String,String> map){

        List<Map<String, Object>> roleListByName =null;
        if(map.get("roleName")!=null&&!map.get("roleName").equals("")){
            //获取用户列表数据
            roleListByName = roleService.getRoleListByName(map.get("roleName"));
        }else{
            roleListByName = new ArrayList<>();
        }
        ResponseResult responseResult=ResponseResult.getResponseResult();
        responseResult.setCode(ResponseResultEnum.SECCESS.getCode());
        responseResult.setResult(roleListByName);

        return responseResult;
    }

}
